home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 January: Mac OS SDK / Dev.CD Jan 96 SDK / Dev.CD Jan 96 SDK1.toast / Development Kits (Disc 1) / AOCE / Development Tools / Sample Code / Digital Signatures / Digital Signature Demo / Source ƒ / CSignedObject.h < prev    next >
Encoding:
C/C++ Source or Header  |  1993-06-11  |  4.4 KB  |  161 lines  |  [TEXT/KAHL]

  1. /*
  2.  * CSignedObject.h
  3.  * Copyright © 1993 Apple Computer Inc.
  4.  * All Rights Reserved
  5.  *
  6.  * This is a Think C class library definition that permits
  7.  * any Think C object to have an attached digital signature.
  8.  * Methods allow you to attach, save, restore, and verify
  9.  * signatures.
  10.  *
  11.  * Note that this class signs objects, which might be any
  12.  * component of an application, such as a cell in a spreadsheet
  13.  * or even the position of an object in a drawing program.
  14.  * In the real world, you would probably use CSignedDataFile
  15.  * where the signature verifies the content of an entire document.
  16.  *
  17.  * Note: errors are returned through the Think Class
  18.  * Library "Failure" routines.
  19.  *
  20.  * Normal usage:
  21.  * Adding a signature to an object:
  22.  *        myObject->itsSignature = new (CSignedObject);
  23.  *        myObject->itsSignature->ISignedObject();
  24.  * Creating a signature:
  25.  *        myObject->itsSignature->SignPrepare();
  26.  *        myObject->itsSignature->ProcessData();
  27.  *        myObject->itsSignature->Sign();
  28.  * Normal usage (verifying an object):
  29.  *        myObject->itsSignature->ReadSignature(myFile);
  30.  *        myObject->itsSignature->VerifyPrepare();
  31.  *        myObject->itsSignature->ProcessData();
  32.  *        myObject->itsSignature->Verify();
  33.  */
  34.  
  35. #define _H_CSignedObject
  36. #include "CSignature.h"
  37.  
  38. struct CSignedObject : CSignature {
  39. private:
  40.         /*
  41.          * itsSignature is the actual signature.
  42.          */
  43.         SIGSignaturePtr                itsSignature;
  44.         /*
  45.          * itsSignatureSize is the size of itsSignature.
  46.          */
  47.         Size                        itsSignatureSize;
  48.  
  49. public:
  50.         void                        ISignedObject(void);
  51.         void                        Dispose(void);
  52.         /*
  53.          * Override SignPrepare so we retain the
  54.          * signature size. See CSignature.h for
  55.          * the parameter definitions.
  56.          */
  57.         Size                        SignPrepare(
  58.             const FSSpec                *signerFile,
  59.             ConstStr255Param            prompt
  60.         );
  61.         /*
  62.          * Sign computes the full signature for the data
  63.          * that was processed by calling ProcessData.
  64.          * statusProc is an optional callback procedure
  65.          * that you can provide to notify the user of
  66.          * the signature creation progress. Specify
  67.          * NULL if you do not wish to provide a callback
  68.          * procedure.
  69.          */
  70.         void                        Sign(
  71.             SIGStatusProcPtr            statusProc
  72.         );
  73.         /*
  74.          * VerifyPrepare initializes the verification
  75.          * process.
  76.          */
  77.         void                        VerifyPrepare(
  78.             SIGStatusProcPtr            statusProc
  79.         );
  80.         /*
  81.          * Verify tests the validity of the specified
  82.          * signature.
  83.          */
  84.         void                        Verify(void);
  85.         /*
  86.          * Process data passes some data through
  87.          * the signer/verifier. Data does *not*
  88.          * need to be in a locked handle.
  89.          */
  90.         void                        ProcessData(
  91.             const void                    *data,
  92.             Size                        dataSize
  93.         );
  94.         /*
  95.          * Return the signature size.
  96.          */
  97.         Size                        GetSignatureSize(void);
  98.         /*
  99.          * Create a signature buffer using the current
  100.          * signature size.
  101.          */
  102.         void                        NewSignature(void);
  103.         /*
  104.          * Dispose of the current signature buffer without
  105.          * disposing of the context.
  106.          */
  107.         void                        DisposeSignature(void);
  108.         /*
  109.          * True if there is an associated signature.
  110.          */
  111.         Boolean                        HasSignature(void);
  112.         /*
  113.          * Fail with an appropriate error (kSIGNoSignature)
  114.          * if there is no signature.
  115.          */
  116.         void                        CheckForSignature(void);
  117.          /*
  118.           * Copy the current signature to the user's buffer.
  119.           * Fail with paramErr if there is no signature or
  120.           * the caller's bufferSize is smaller than the
  121.           * current signature size. Return the actual
  122.           * signature size.
  123.           */
  124.          Size                        CopySignatureToUserBuffer(
  125.              void                        *buffer,
  126.              Size                        bufferSize
  127.          );
  128.          /*
  129.           * Create a signature buffer using the information
  130.           * provided by the caller. This is needed if an
  131.           * object's signature is stored/restored by the
  132.           * application.
  133.           */
  134.          void                        MakeSignatureFromUserBuffer(
  135.              void                        *buffer,
  136.              Size                        bufferSize
  137.          );
  138.          /*
  139.           * Write a signature to an existing file. You would
  140.           * call this as part of your "save this object"
  141.           * process. aFile is the Think C Class file object.
  142.          *
  143.          * The function works correctly even if there is no
  144.          * current signature (it writes a zero-length record
  145.          * that is understood by ReadSignature).
  146.           */
  147.         void                        WriteSignature(
  148.             CDataFile                    *aFile
  149.         );
  150.         /*
  151.          * Read a signature from an open file. You would
  152.          * call this as part of your "restore this object"
  153.          * process. Fails with paramErr if the next thing
  154.          * read is not a signature. Succeeds without error
  155.          * if there was no signature written.
  156.          */ 
  157.         void                        ReadSignature(
  158.             CDataFile                    *aFile
  159.         );
  160. };
  161.